package com.kstudio.videocapture.listfile;

import java.io.File;


public class KFileListItem {
    public static final int FOLDERUP    = 0x0001;
    public static final int FOLDER      = 0x0002;
    public static final int FILE        = 0x0003;
    public static final int VIDEO       = 0x0004;
    public static final int PICTURE     = 0x0005;

    public static final String[] VideoExtiontion = {"3GP","3gp","MP4","mp4","MKV","mkv"};
    public static final String[] PictureExtiontion = {"PNG","png","JPG","jpg","BMP","bmp"};

    private String path;
    private int filetype;
    private int duration;
    private boolean filecheck;

    public KFileListItem(String path) {
    	this(path, FILE);
    }

    public KFileListItem(String path, int filetype) {
        this.path = path;
        this.filetype = filetype;
        this.duration = 0;
        this.filecheck = false;
    }

    /* set function */
    public void setDuration(int duration) {
        this.duration = duration;
    }

    public void setFileType(int attribute) {
        this.filetype = attribute;
    }

    public void setFileCheck(boolean b) {
    	this.filecheck = b;
    }

    /* get function */
    public String getPath() {
        return path;
    }

    public String getName() {
        int separatorIndex = path.lastIndexOf(File.separator);
        return (separatorIndex < 0) ? path : path.substring(separatorIndex + 1, path.length());
    }

    public int getDuration() {
        return duration;
    }

    public int getFileType() {
        return filetype;
    }

    public static int getFileType(String path) {
        int fileType = FILE;

        String extention;
        int extentionIndex = path.lastIndexOf(String.valueOf('.'));

        if(extentionIndex > 0) {
            extention = path.substring(extentionIndex + 1);
            for(String ex : VideoExtiontion) {
                if(extention.equals(ex)) {
                    fileType = KFileListItem.VIDEO;
                    break;
                }
            }
            for(String ex : PictureExtiontion) {
                if(extention.equals(ex)) {
                    fileType = KFileListItem.PICTURE;
                    break;
                }
            }
        }

        return fileType;
    }

    public boolean getFileCheck() {
    	return filecheck;
    }
}
